package com.cangxuan.manage.service.impl;

import com.cangxuan.manage.bean.Page;
import com.cangxuan.manage.dao.IArticleDao;
import com.cangxuan.manage.entity.Article;
import com.cangxuan.manage.service.IArticleService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

/**
 *Author:罗健
 */
@Service
public class ArticleServiceImpl implements IArticleService {
    IArticleDao articleDao;
    @Autowired
    public void setArticle(IArticleDao articleDao) {
        this.articleDao = articleDao;
    }

    @Override
    public Page<Article> page(int pageIndex, int pageSize, int typeId,String title) {
        Page<Article> articlePage = new Page<>(pageIndex, pageSize);
        articlePage.setRecords(articleDao.selectArticleByTypeId(pageIndex, pageSize,typeId,title));
        articlePage.setTotal(articleDao.selectCount(title,typeId));
        return articlePage;
    }
    @Override
    public boolean save(Article article) {
        return article.getId() == 0 ? articleDao.insertArticle(article) > 0 : articleDao.up(article) > 0;
    }

    @Override
    public boolean remove(int id) {
        return articleDao.deleteArticle(id)>0;
    }


}
